# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=glib-networking
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.48.1
pkgrel=1
pkgdesc="Network-related GIO modules for glib (mingw-w64)"
arch=(any)
url="https://download.gnome.org/sources/libsoup"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "intltool")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-p11-kit"
         "${MINGW_PACKAGE_PREFIX}-xz")
options=('staticlibs' 'strip')
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        0001-dont-overwrite-prefix-remain-relative.mingw.patch
        0001-hack-path.patch
        0002-relative-system-ca-file.mingw.patch)
sha256sums=('cf9923ab9860011c5af6d58b0aa1db693d353f2008014a3dcb07af1952bea44a'
            '78c41b37e3cf3222d9181b61398ff0303f852b00b9970b49e752baf67c5f30dd'
            '50c42a5818ff16bd3210c1b2ed9974fc63474146cc987b9e4302dba05788caa3'
            '5a1bc2fd37c1ba4af26aa91efaf1153f0cdd24f1a14c5dcdbebbc3ba7cab589a')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #patch -p1 -i ${srcdir}/0001-dont-overwrite-prefix-remain-relative.mingw.patch
  patch -p1 -i ${srcdir}/0001-hack-path.patch
  patch -p1 -i ${srcdir}/0002-relative-system-ca-file.mingw.patch
  autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --without-libproxy \
    --without-gnome-proxy \
    --with-ca-certificates=ssl/certs/ca-bundle.crt \
    --with-pkcs11

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gio/modules/*.a

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
